package com.wangshouyu.mp.micro.session;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.annotations.SerializedName;
import com.wangshouyu.mp.micro.base.response.BaseResponse;

import java.io.Serializable;
import java.util.Objects;

/**
 * @author 王守钰
 * @description 小程序Session
 * @date 2020/8/19 9:05
 */
public class MicroSession extends BaseResponse implements Serializable {

    /**
     * 用户唯一标识
     */
    @SerializedName(value = "openid")
    @JsonProperty(value = "openid")
    @JSONField(name = "openid")
    private String openId;

    /**
     * 会话密钥
     */
    @SerializedName(value = "session_key")
    @JsonProperty(value = "session_key")
    @JSONField(name = "session_key")
    private String sessionKey;

    /**
     * 用户在开放平台的唯一标识符
     * 在满足 UnionID 下发条件的情况下会返回
     */
    @SerializedName(value = "unionid")
    @JsonProperty(value = "unionid")
    @JSONField(name = "unionid")
    private String unionId;


    public String getOpenId() {
        return openId;
    }

    public void setOpenId(String openId) {
        this.openId = openId;
    }

    public String getSessionKey() {
        return sessionKey;
    }

    public void setSessionKey(String sessionKey) {
        this.sessionKey = sessionKey;
    }

    public String getUnionId() {
        return unionId;
    }

    public void setUnionId(String unionId) {
        this.unionId = unionId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MicroSession that = (MicroSession) o;
        return Objects.equals(openId, that.openId) && Objects.equals(sessionKey, that.sessionKey) && Objects.equals(unionId, that.unionId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(openId, sessionKey, unionId);
    }

    @Override
    public String toString() {
        return "MicroSession{" +
                "openId='" + openId + '\'' +
                ", sessionKey='" + sessionKey + '\'' +
                ", unionId='" + unionId + '\'' +
                '}';
    }
}
